package com.rongzhe.house.article.controller;

import com.rongzhe.house.article.bo.ArticleBo;
import com.rongzhe.house.article.entity.Article;
import com.rongzhe.house.article.service.ArticleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Chengjia
 * @date 2018/3/3 11:33
 */
@RequestMapping("article")
@Controller
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @ApiOperation(value = "详细", notes = "article", httpMethod = "POST")
    @RequestMapping(value = "/detail", method = RequestMethod.POST)
    @ResponseBody
    public ArticleBo detail(Model model, Article article) {
        return articleService.selectByID(article.getId());
    }

    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    public String index(Model model, @RequestParam("id") Integer id) {
        model.addAttribute("detail", articleService.selectByID(id));
        return "articleDetails";
    }

}
